package com.knight.study.patterns.tujie.iterator;

/**
 * @Author knight
 * @Date 2024/9/5 16:06
 */

public class BookShelfIterator implements Iterator{
    @Override
    public boolean hasNext() {
        if (index < bookShelf.getLength()) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Object next() {
        final Book bookAt = bookShelf.getBookAt(index);
        this.index++;
        return bookAt;
    }

    private BookShelf bookShelf;
    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

}
